home *** CD-ROM | disk | FTP | other *** search
/ Aminet 46 / Aminet 46 (2001)(GTI - Schatztruhe)[!][Dec 2001].iso / Aminet / text / bfont / BTopaz.lha / BTopaz / Primer01.c < prev    next >
C/C++ Source or Header  |  2001-09-19  |  6KB  |  183 lines

  1. /* This example demonstrates how to open a disk font (BTopaz, 8)   */
  2. /* and prints some characters with the new font in a window. Note! */
  3. /* The font "BTopaz" must exist in the systems Fonts: directory or */
  4. /* you will receive an error message!                              */
  5.  
  6. #include <intuition/intuitionbase.h>
  7.  
  8. struct Intuition *IntuitionBase; /* Running under Intuition. */
  9. struct GfxBase *GfxBase;         /* Move() and Text().       */
  10. struct Library *DiskfontBase;    /* OpenDiskFont() etc.      */
  11. /* NOTE! If you want to use the functions OpenDiskFont() or  */
  12. /* AvailFonts() you have to open the Diskfont Library!       */
  13.  
  14. UBYTE ju=0xFE, ja=0xFF; /* The source can't be compiled with the last 2
  15.                            letters of the Bulgarian charset, so this is
  16.                            Simple workaround. Use these codes intead.
  17.                            Òake care of this when writting BG messages */
  18.  
  19. /* The new font's attributes: */
  20. struct TextAttr my_font_attr=
  21. {
  22.   "BTopaz.font",/* Name of the font.  */
  23.   8,            /* Height (in pixels) */
  24.   FS_NORMAL,    /* Style              */
  25.   FPF_DISKFONT  /* Exist on Disk.     */
  26. };
  27.  
  28. /* Pointer to our new font: */
  29. struct TextFont *my_font;
  30.  
  31.  
  32. /* Declare a pointer to a Window structure: */ 
  33. struct Window *my_window;
  34.  
  35. /* Declare and initialize your NewWindow structure: */
  36. struct NewWindow my_new_window=
  37. {
  38.   0,             /* LeftEdge    x position of the window. */
  39.   12,            /* TopEdge     y positio of the window. */
  40.   640,           /* Width       640 pixels wide. */
  41.   100,           /* Height      100 lines high. */
  42.   0,             /* DetailPen   Text should be drawn with colour reg. 0 */
  43.   1,             /* BlockPen    Blocks should be drawn with colour reg. 1 */
  44.   CLOSEWINDOW,   /* IDCMPFlags  The window will give us a message if the */
  45.                  /*             user has selected the Close window gad. */
  46.   SMART_REFRESH| /* Flags       Intuition should refresh the window. */
  47.   WINDOWCLOSE|   /*             Close Gadget. */
  48.   WINDOWDRAG|    /*             Drag gadget. */
  49.   WINDOWDEPTH|   /*             Depth arrange Gadgets. */
  50.   ACTIVATE,      /*             The window should be Active when opened. */
  51.   NULL,          /* FirstGadget No Custom gadgets. */
  52.   NULL,          /* CheckMark   Use Intuition's default CheckMark. */
  53.   "Wow! This BTopaz font works!",/* Title       Title of the window. */
  54.   NULL,          /* Screen      Connected to the Workbench Screen. */
  55.   NULL,          /* BitMap      No Custom BitMap. */
  56.   0,             /* MinWidth    No sizing gadget. */
  57.   0,             /* MinHeight          -"-        */
  58.   0,             /* MaxWidth           -"-        */
  59.   0,             /* MaxHeight          -"-        */
  60.   WBENCHSCREEN   /* Type        Connected to the Workbench Screen. */
  61. };
  62.  
  63. void clean_up();
  64.  
  65. main()
  66. {
  67.   BOOL close_me;                   /* Used in the loop.       */
  68.   ULONG class;                     /* IDCMP flag.             */
  69.   struct IntuiMessage *my_message; /* IntuiMessage structure. */
  70.  
  71.  
  72.   /* Open the necessary libraries: */
  73.   IntuitionBase = (struct IntuitionBase *)
  74.     OpenLibrary( "intuition.library", 0 );
  75.   if( !IntuitionBase )
  76.     clean_up( "Could not open Intuition library!" );
  77.  
  78.   GfxBase = (struct GfxBase *)
  79.     OpenLibrary( "graphics.library", 0 );
  80.   if( !GfxBase )
  81.     clean_up( "Could not open Graphics library!" );
  82.  
  83.   DiskfontBase = (struct DiskfontBase *)
  84.     OpenLibrary( "diskfont.library", 0 );
  85.   if( !DiskfontBase )
  86.     clean_up( "Could not open Diskfont library!" );
  87.  
  88.  
  89.   /* Open a window in which we will display the new font: */
  90.   my_window = (struct Window *) OpenWindow( &my_new_window );
  91.   
  92.   /* Have we opened the window succesfully? */
  93.   if(my_window == NULL)
  94.     clean_up( "Could not open the window!" );
  95.  
  96.  
  97.   /* Set colour and draw mode: */
  98.   SetAPen( my_window->RPort, 1 );
  99.   SetDrMd( my_window->RPort, JAM1 );
  100.  
  101.  
  102.   /* Try to open a disk font: */
  103.   my_font = (struct TextFont *)
  104.     OpenDiskFont( &my_font_attr );
  105.  
  106.   /* Have we opened the font successfully? */
  107.   if( !my_font )
  108.     clean_up( "Could not open the font!" );
  109.  
  110.  
  111.   /* Change the window's default font: */
  112.   SetFont( my_window->RPort, my_font );
  113.  
  114.  
  115.   /* Position the cursor, and print some characters: */
  116.  
  117.   Move( my_window->RPort, 85, 27 );
  118.   Text( my_window->RPort, "Òîçè êðàòúê ïðèìåð ïîêàçâà èçïîëçâàíåòî íà BTopaz øðèôòà", 56 );
  119.  
  120.   Move( my_window->RPort, 85, 42 );
  121.   Text( my_window->RPort, "â åëåìåíòàðíà ïðîãðàìà. Èçõîäíèÿ êîä íà C å â Primer01.c", 56 );
  122.  
  123.   Move( my_window->RPort, 85, 69 );
  124.   Text( my_window->RPort, "ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÜÚÞß", 56 );
  125.  
  126.   Move( my_window->RPort, 85, 84 );
  127.   Text( my_window->RPort, "abcdefghijklmnopqrstuvwxyzàáâãäåæçèéêëìíîïðñòóôõö÷øùüú", 54 );
  128.   Text( my_window->RPort, &ju,1); Text( my_window->RPort, &ja,1);
  129.  
  130.  
  131.   /* Wait until the user closes the window: */
  132.   close_me = FALSE;
  133.   while( close_me == FALSE )
  134.   {
  135.     /* Wait until we have recieved a message: */
  136.     Wait( 1 << my_window->UserPort->mp_SigBit );
  137.  
  138.     /* Collect the message: */
  139.     while( (my_message = (struct IntuiMessage *) GetMsg( my_window->UserPort )) )
  140.     {
  141.       /* After we have collected the message we can read it, and save any */
  142.       /* important values which we maybe want to check later: */
  143.       class = my_message->Class;
  144.  
  145.       /* After we have read it we reply as fast as possible: */
  146.       /* REMEMBER! Do never try to read a message after you have replied! */
  147.       /* Some other process has maybe changed it. */
  148.       ReplyMsg( my_message );
  149.  
  150.       /* Check which IDCMP flag was sent: */
  151.       if( class == CLOSEWINDOW )
  152.         close_me=TRUE; /* The user selected the Close window gadget! */  
  153.     }
  154.   }
  155.  
  156.  
  157.   clean_up( "The End" );
  158. }
  159.  
  160. void clean_up( message )
  161. STRPTR message;
  162. {
  163.   if( my_window )
  164.     CloseWindow( my_window );
  165.  
  166.   if( my_font )
  167.     CloseFont( my_font );
  168.  
  169.   if( DiskfontBase )
  170.     CloseLibrary( DiskfontBase );
  171.  
  172.   if( GfxBase )
  173.     CloseLibrary( GfxBase );
  174.  
  175.   if( IntuitionBase )
  176.     CloseLibrary( IntuitionBase );
  177.   
  178.   printf( "%s\n", message );
  179.  
  180.   exit();
  181. }
  182.  
  183.